Skip to content

Conversation

@yanok
Copy link
Contributor

@yanok yanok commented Oct 30, 2025

Debug info stores the path to the directory where the source is located and that causes problem with getting reproducible build results if ran from different work directories.

Traditionally people solve that by controlling the build environment, such that sources are always at the fixed location. But this can sometimes be undesirable (for example with bazel, where each build action runs in a sandbox with a hash in the path name), so clang supports the -fdebug-prefix-map option to control this.

This PR implement the same option in LDC.

yanok added 2 commits November 1, 2025 17:34
Try to follow clang, accepting pairs of <old>=<new> paths.
This is required to have reproducible builds without remapping
the source code directory to a fixed location (for example in Bazel,
where the source code for every build action will end up in a
sanbox directory with some hash in the path name).

Try to keep the implementation as close as possible to what clang
does.
@yanok yanok force-pushed the yanok/debug-prefix-map branch from 5045485 to 9edb6d4 Compare November 1, 2025 16:35

std::string DIBuilder::remapDIPath(llvm::StringRef path) {
for (const auto &[from, to] : opts::debugPrefixMap) {
if (path.starts_with(from)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starts_with looks dangerous, what if I map "some/path="other/thing", does that mean that "some/path_more" also matches and is remapped?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(could be checked in a test case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but this is what clang does. I guess in the most (only?) use cases this is going to be some "root" path, so we don't expect sources from root_some to be passed to the compiler. Cautious people can do some/path/=other/thing/. It's easy to enforce this in the code, but I don't want to diverge from clang...

@JohanEngelen
Copy link
Member

Don't forget to add testcase(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants